<?php
class YouNet_Form_Element_BannerLink extends Zend_Form_Element_Text
{
	const URL_PATTERN				= '/^(http:\/\/|https:\/\/|www\.)([\w\d\-]+\.){1,}[\w]{2,}(\/[\S]*)*$/';
	private $_specs = 'link';
	private $_options = array(
		'label'		=> "Banner link",
		'filters'	=> array('StringTrim')
	);
	
	public function __construct($specs = NULL, $options = NULL)
	{
		if (isset($specs))
			$this->_specs = $specs;
		if (isset($options))
			$this->_options = array_merge($this->_options, $options);
		
		parent::__construct($this->_specs, $this->_options);
		$this->addValidator('regex', true, 
            array(
                'pattern' =>self::URL_PATTERN, 
                'messages'=>array(
                    'regexNotMatch'=>"Banner link is invalid."
                )
            )
		);
		$maxLengthValidator = new YouNet_Validate_StringLength(array('max' => 255));
		$maxLengthValidator->setMessage(sprintf(YouNet_Util::translate("%s is more than %s characters long."), "Banner link", 255),Zend_Validate_StringLength::TOO_LONG);
		$this->addValidator($maxLengthValidator);
	}
}